package com.hwadee.backend.entity.HealthRecord;

import lombok.Getter;
import lombok.Setter;

import java.sql.Date;

// 过敏史
@Getter
@Setter
public class AllergyHistory extends HealthRecord {
    // 过敏原
    private String allergen;
    // 禁用药物
    private String forbiddenDrugs;
    // 治疗药物
    private String treatmentDrugs;
    // 避免方式
    private String avoidanceMethod;
    // 备注
    private String remarks;

    public AllergyHistory() {
    }

    public AllergyHistory(int recordId, Date recordDate, String recordType, String detail) {
        super(recordId, recordDate, recordType, detail);
        splitDetail(detail);
        super.setDetail(null); // 将 detail 置为空值
    }

    /**
     * 从 detail 字符串中解析过敏原、禁用药物、治疗药物、避免方式和备注
     * @param detail 包含过敏原、禁用药物、治疗药物、避免方式和备注的字符串，用 | 分隔
     */
    private void splitDetail(String detail) {
        String[] parts = detail.split("\\|");
        if (parts.length >= 1) {
            this.allergen = parts[0];
        }
        if (parts.length >= 2) {
            this.forbiddenDrugs = parts[1];
        }
        if (parts.length >= 3) {
            this.treatmentDrugs = parts[2];
        }
        if (parts.length >= 4) {
            this.avoidanceMethod = parts[3];
        }
        if (parts.length >= 5) {
            this.remarks = parts[4];
        }
    }


}